package main

import (
	"log"
	"os"

	"gitee.com/huanghua_2017/blade/build"
	lcli "gitee.com/huanghua_2017/blade/server/cli"
	cli "github.com/urfave/cli/v2"
)

func main() {
	local := []*cli.Command{
		lcli.RunCmd,
		lcli.InfoCmd,
		lcli.EchoCmd,
	}

	for _, cmd := range local {
		cmd := cmd
		originBefore := cmd.Before
		cmd.Before = func(cctx *cli.Context) error {

			if originBefore != nil {
				return originBefore(cctx)
			}
			return nil
		}
	}

	app := &cli.App{
		Name:    "server",
		Usage:   "HTTP代理服务端程序",
		Version: build.Version,
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name:    "server_storage",
				EnvVars: []string{"SERVER_STORAGE"},
				Hidden:  true,
				Value:   "server_storage",
			},
		},

		Commands: local,
	}
	app.Setup()

	if err := app.Run(os.Args); err != nil {
		log.Printf("%+v\n", err)
	}
}
